package zerous.mytest;
import android.support.v4.app.*;
import android.view.*;
import android.os.*;
import android.widget.*;
import java.util.*;
import android.content.*;

public class PasswordFragment extends Fragment implements View.OnClickListener
{
	EditText s, p;
	TextView rls;
	Button c;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		final View ctx = inflater.inflate(R.layout.fragment_password, container, false);
		s = (EditText)ctx.findViewById(R.id.special);
		p = (EditText)ctx.findViewById(R.id.password);
		rls = (TextView)ctx.findViewById(R.id.viewPassword);
		
		rls.setOnClickListener(this);

		c = (Button)ctx.findViewById(R.id.createPassword);
		c.setOnClickListener(this);
		return ctx;
	}
	
	public void setMenu(Menu menu) {
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.createPassword: {
				String seed = s.getEditableText().toString();
				String password = p.getEditableText().toString();
				long seedL = 0, passL = 0;
				for (int i = 0;i < seed.length();++i) {
					seedL += (long)seed.charAt(i);
				}

				for (int i = 0;i < password.length();++i) {
					passL += (long)password.charAt(i);
				}
				Random rnd = new Random(seedL + passL);

				String rlt = seed;
				for (int i = 0;i < 10;++i) {
					rlt += (char)(48 + rnd.nextFloat() * (122 - 48));
				}
				ClipboardManager mgr = getActivity().getSystemService(ClipboardManager.class);
				mgr.setText(rlt);
				Toast.makeText(getActivity(), "已复制到剪贴板,直接粘贴即可", Toast.LENGTH_SHORT).show();

				rls.setText(rlt);

				/*AlertDialog.Builder builder = new AlertDialog.Builder(this);
				 builder.setTitle("内啥，是不是要保存密码？");
				 builder.setView(t);
				 builder.setNegativeButton(android.R.string.ok, this);*/
				break;
			}
				
			case R.id.viewPassword: {
				ClipboardManager mgr = getActivity().getSystemService(ClipboardManager.class);
				mgr.setText(rls.getText());
				Toast.makeText(getActivity(), "已复制到剪贴板,直接粘贴即可", Toast.LENGTH_SHORT).show();
				break;
			}
				
		}
		
		
	}
}
